package ebuy.com.cotroller;

import ebuy.com.pojo.Shopping;
import ebuy.com.server.Easybuy_userserver;
import ebuy.com.server.Shoppingserver;
import ebuy.com.util.RespBean;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Shoppingcotroller {
    @Autowired
    private Shoppingserver shoppingserver;
    @Autowired
    private Easybuy_userserver easybuy_userserver;
    @GetMapping("/getshopp")
    public RespBean Getshopping(@RequestParam("commoditysid") Integer commoditysid,@RequestParam("usersname")String usersname,Integer numberofgoods){
        System.out.println("======================添加到购物车里面=================================");
        System.out.println(commoditysid+"----"+usersname);
        Integer querybyusername = easybuy_userserver.Querybyusername(usersname);
        System.out.println(querybyusername);
        Shopping shoppingn=new Shopping();
       shoppingn.setUsersid(querybyusername);
       shoppingn.setNumberofgoods(numberofgoods);
        shoppingn.setCommoditysid(commoditysid);


        int addshoppingcart = shoppingserver.Addshoppingcart(shoppingn);

        System.out.println(addshoppingcart);
        return RespBean.success("添加成功",addshoppingcart);
    }
    @GetMapping("/deleteshoppid")
    public RespBean Deleteshoppingcartbasedonid(@RequestParam("id")Integer id){
        int deleteshoppingcart = shoppingserver.Deleteshoppingcart(id);
        return RespBean.success("删除成功",deleteshoppingcart);
    }
}
